package test.nettys.nio;

import java.nio.ByteBuffer;

/**
 * @Author wangshaopeng
 * @Date 2021/7/19
 */
public class NioTest6 {


    public static void main(String[] args) {

        ByteBuffer buffer = ByteBuffer.allocate(10);

        for (int i = 0; i < buffer.capacity(); i++) {
            buffer.put((byte) i);
        }


        buffer.position(1);
        buffer.limit(5);

        ByteBuffer slice = buffer.slice();


        int i = 0;
        while (slice.hasRemaining()) {
            byte b = slice.get();
            slice.put(i++, (byte) (b * 2));
        }


        buffer.position(0);
        buffer.limit(10);


        while (buffer.hasRemaining()) {
            System.out.println(buffer.get());
        }



    }
}
